#include<iostream>
using namespace std;

typedef struct BiThrNode
{
    char data;
    struct BiThrNode *lchild,*rchild;
    int LTag,RTag;
}BiThrNode,*BiThrTree;


BiThrNode *pre=new BiThrNode;

void CreateBiTree(BiThrTree &T)
{
    char ch;
    cin >> ch;
    if(ch=='#')  T=NULL;
    else
    {
        T=new BiThrNode;
        T->data=ch;
        CreateBiTree(T->lchild);
        CreateBiTree(T->rchild);
    }
}

void InThreading(BiThrTree p);
void InOrderTraverse_Thr(BiThrTree T);

int main()
{
    freopen("6-5.in","r",stdin);
    pre->RTag=1;
    pre->rchild=NULL;
    BiThrTree tree;
    CreateBiTree(tree);
    InThreading(tree);
    InOrderTraverse_Thr(tree);
    return 0;
}
/* 请在这里填写答案 */
void InThreading(BiThrTree p)
{
    if(p)
    {
        InThreading(p->lchild);
        if(!p->lchild)
        {
            p->LTag=1;
            p->lchild=pre;
        }
        if(!pre->rchild)
        {
            pre->RTag=1;
            pre->rchild=p;
        }
        pre=p;
        InThreading(p->rchild);
    }
}
void InOrderTraverse_Thr(BiThrTree T)
{
    BiThrTree p=T;
    while(p!=NULL)
    {
        while(!p->LTag)
            p=p->lchild;
        printf("%c",p->data);
        while(p->RTag&&p->rchild!=NULL)
            p=p->rchild,printf("%c",p->data);
        p=p->rchild;
    }
}